package com.itheima.TCP;

import java.io.*;
import java.net.Socket;

public class ClientDemo02 {
    public static void main(String[] args) throws IOException {
        Socket socket = new Socket("127.0.0.1",10086);
        OutputStream os = socket.getOutputStream();
        //用转换流将字节流转为字符缓冲流
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(os));
        bw.write("Hello,你好啊，我是...");
        bw.flush();
        //使用shutdownOutput()，仅仅关闭输出流.并写一个结束标记,对socket没有任何影响
        socket.shutdownOutput();
        //如果在这里关流,会导致整个socket都无法使用,会抛出下面的异常
        //SocketException: Socket is closed
        //bw.close();

        InputStream is = socket.getInputStream();
        //用转换流将字节流转为字符缓冲流
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String s = br.readLine();
        System.out.println(s);

        br.close();
        socket.close();
    }
}
